using System;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;

namespace Intuipic.Navigation
{
	public partial class ToolTip
	{
		public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text",
			typeof(string),
			typeof(ToolTip));

		public static readonly DependencyProperty GestureTextProperty = DependencyProperty.Register("GestureText",
			typeof(string),
			typeof(ToolTip));

		public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command",
			typeof(RoutedCommand),
			typeof(ToolTip));

		public string Text
		{
			get
			{
				return GetValue(TextProperty) as string;
			}
			set
			{
				SetValue(TextProperty, value);
			}
		}

		public string GestureText
		{
			get
			{
				return GetValue(GestureTextProperty) as string;
			}
			set
			{
				SetValue(GestureTextProperty, value);
			}
		}

		public RoutedCommand Command
		{
			get
			{
				return GetValue(CommandProperty) as RoutedCommand;
			}
			set
			{
				SetValue(CommandProperty, value);
			}
		}

		public ToolTip()
		{
			Resources["GestureTextConverter"] = new GestureTextConverter();
			InitializeComponent();
		}

		private sealed class GestureTextConverter : IValueConverter
		{
			public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
			{
				string gestureText = value as string;

				if (!string.IsNullOrEmpty(gestureText))
				{
					return string.Format("({0})", gestureText);
				}

				return DependencyProperty.UnsetValue;
			}

			public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
			{
				throw new NotSupportedException();
			}
		}
	}
}